<template>
  <div>
    <!-- '需求及完成情况分析 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="wkcMonthTargetQuery"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onColumnsChange="(columns) => (this.columns = columns)"
        :isSelectColumn="false"
      >
        <!--        <template slot="controls" slot-scope="props">-->
        <!--          <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>-->
        <!--        </template>-->
      </FilterTable>
    </Spin>
  </div>
</template>
<script>
import moment from 'moment';
import { queryList, getSeriesList } from '@/api/omSale/salesPlan/MonthTargetQuery';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'MonthTargetQuery',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: { isDealer: 10041001, targetDate: moment().subtract(-1, 'months').format('YYYY-MM') },
      exportLoading: false,
    };
  },
  created() {
    this.getSeriesData();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    async getSeriesData() {
      const res = await getSeriesList();
      if (res.resultCode === 200) {
        res.data.map((x) => {
          this.topFilterList.find((item) => item.fieldName == 'seriesId').itemList.push({ text: x.seriesName, value: x.seriesId });
        });
      }
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    createdFrom() {
      return [
        {
          type: 'DATE',
          label: '指标月份',
          fieldName: 'targetDate',
          initialValue: moment().subtract(-1, 'months').format('YYYY-MM'),
          dateType: 'month',
          clearable: true,
        },
        {
          type: 'SELECT',
          label: '类型',
          fieldName: 'targetType',
          placeholder: '请选择',
          itemList: this.createDictList('2403'),
        },
        {
          type: 'SELECT',
          label: '车系名称',
          fieldName: 'seriesId',
          placeholder: '请选择',
          itemList: [],
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (props) => {
            //编码转汉字
            return <span>{this.createDictText(props.row.status, '2402')}</span>;
          },
        },
        {
          title: '销售区域',
          dataIndex: 'deptName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '类型',
          dataIndex: 'targetType',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (props) => {
            //编码转汉字
            return <span>{this.createDictText(props.row.targetType, '2403')}</span>;
          },
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input',
          // render: props => {    //编码转汉字
          //   return <span>{this.getSeriesName(props.row.seriesId)}</span>;
          // }
        },
        {
          title: '物料编码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '指标月份',
          dataIndex: 'targetDate',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '任务数量',
          dataIndex: 'targetNum',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '下发日期',
          dataIndex: 'assignDate',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '下发人',
          dataIndex: 'assignPersonName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
  },
};
</script>
